//===========================================================================================
#include <dylab/utils/geometry/TriangleGeometry3.h>
//-----------------------------------------------------------------------------
void runPointInTriangleTest(const TriangleGeometry3 & _triGeom, const Vector3 & _p, const TriangleGeometry3::pointcls_t & _correctCls)
{
    TriangleGeometry3::pointcls_t pointCls = _triGeom.classifyPoint(_p);

    // test, if cetner is inside based on barycentric coords    
    DYLAB_LOGF3("\t\t classifyPoint(%1%) = %2% (correctCls = %3%)", _p, pointCls, _correctCls);

    // verify point classification
    DYLAB_VERIFY(pointCls.first == _correctCls.first);
    switch (pointCls.first)
    {
    case Math::POINTCLS_VERTEX:
        DYLAB_VERIFY(pointCls.second.vertexIdx == _correctCls.second.vertexIdx);
        break;
    case Math::POINTCLS_EDGE:
        DYLAB_VERIFY(pointCls.second.edgeIdx == _correctCls.second.edgeIdx);
        break;
    }    
}
//-----------------------------------------------------------------------------
void runTriangleTests(const TriangleGeometry3 & _triGeom)
{ DYLAB_TRACE_CALLS

    // log tested triangle info
    DYLAB_LOGF("Testing _triGeom: %1% ... ", _triGeom);

    // print its vertices
    for (TriangleGeometry3::VertexIdxIterator vertexIdx; vertexIdx.isValid(); vertexIdx++)
    {
        DYLAB_LOGF("\tcontains vertex: %1%", _triGeom[vertexIdx]);

        // and check, if they are inside
        runPointInTriangleTest(_triGeom, _triGeom[vertexIdx], TriangleGeometry3::pointcls_t(Math::POINTCLS_VERTEX, *vertexIdx));
    }

    DYLAB_LOG("\n");

    // now print its edges ...
    for (TriangleGeometry3::EdgeIdxIterator edgeIdx; edgeIdx.isValid(); edgeIdx++)
    {
        DYLAB_LOGF("\tcontains edge: %1%", _triGeom.getEdgeGeometry(edgeIdx));

        // and check, if their mid-points are inside
        runPointInTriangleTest(_triGeom, _triGeom.getEdgeGeometry(edgeIdx).computeCenter(), TriangleGeometry3::pointcls_t(Math::POINTCLS_EDGE, *edgeIdx));
    }

    DYLAB_LOG("\n");

    // compute value & volume of the triangle
    DYLAB_LOGF("\tcomputeArea() = %1%", _triGeom.computeArea());

    // degeneration test
    DYLAB_LOGF("\tisDegenerated() = %1%", _triGeom.isDegenerated());
    DYLAB_VERIFY(!_triGeom.isDegenerated());

    // compute triangle center
    DYLAB_LOGF("\tcomputeCenter() = %1%", _triGeom.computeCenter());

    // compute barycetric coords of the its cetner
    DYLAB_LOGF("\tcomputeBarycetricCoords(computeCenter()) = %1%", _triGeom.computeBarycentricCoords(_triGeom.computeCenter()));
    DYLAB_VERIFY(_triGeom.computeBarycentricCoords(_triGeom.computeCenter()).almostEqual(Vector3(Math::ONE, Math::ONE, Math::ONE) / DYLAB_R(3)));

    // check, if the center is inside its triangle
    runPointInTriangleTest(_triGeom, _triGeom.computeCenter(), TriangleGeometry3::pointcls_t(Math::POINTCLS_INNER, TriangleGeometry3::FeatureIdx()));
}
//===========================================================================================